package leetcode;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-5-31
 * Time: 下午7:36
 * To change this template use File | Settings | File Templates.
 */
public class Same_Tree {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p==null && q==null)
            return true;
        else if(p!=null && q!=null){
            if(p.val==q.val){
                return (isSameTree(p.left,q.left) && isSameTree(p.right,q.right));
            }
            else
                return false;
        }
        else
            return false;
    }
    public static void main(String[] args){
        TreeNode node1 = new TreeNode(3);
        node1.right = new TreeNode(2);
        node1.left = new TreeNode(1);

        TreeNode node2 = new TreeNode(3);
        node2.left = new TreeNode(2);
        node2.left.right = new TreeNode(1);
        Same_Tree same_tree = new Same_Tree();
        System.out.print(same_tree.isSameTree(node1,node2));
    }
}
